home *** CD-ROM | disk | FTP | other *** search
Wrap
/*********************************************************************** * * sample.c * * The example of using RWUSER.DLL library. Proxima Systems ***********************************************************************/ #include "SAMPLE.h" #include "rwuser.h" int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { MSG msg; int nRc; strcpy(szAppName, "SAMPLE"); hInst = hInstance; if(!IsRWINDrv(hInst)) return FALSE; if(!hPrevInstance) { if ((nRc = nCwRegisterClasses()) == -1) { LoadString(hInst, IDS_ERR_REGISTER_CLASS, szString, sizeof(szString)); MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION); return nRc; } } hWndMain = CreateWindow( szAppName, "Sample", WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN | WS_OVERLAPPED, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL); if(hWndMain == NULL) { LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szString)); MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION); return IDS_ERR_CREATE_WINDOW; } ShowWindow(hWndMain, nCmdShow); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } CwUnRegisterClasses(); return msg.wParam; } BOOL IsRWINDrv (HANDLE hInstance) { char szBuffer [128] ; GetPrivateProfileString ("boot", "keyboard.drv", " ", szBuffer, sizeof(szBuffer), "system.ini") ; if (lstrcmpi ((LPSTR)szBuffer, "kbdrwin.drv") != 0) { MessageBox (GetFocus(), "This program requires R-WIN keyboard driver.", szAppName, MB_ICONSTOP | MB_OK) ; return FALSE ; } return TRUE ; } LONG FAR PASCAL WndProc(HWND hWnd, WORD Message, WORD wParam, LONG lParam) { HMENU hMenu=0; HBITMAP hBitmap=0; HDC hDC; PAINTSTRUCT ps; int nRc=0; WORD wCurMode ; BYTE bCurHotkey ; BYTE bMaxHotkeys ; char szHotkey[32] ; char szLayoutName[64] ; WORD wRetValue ; BOOL bPriDllLoaded ; BOOL bSecDllLoaded ; static char CurModeString[128] ; static char CurHotkeyString[128] ; static char PriLibraryString[128] ; static char SecLibraryString[128] ; switch (Message) { case WM_COMMAND: switch (wParam) { case IDM_F_GETKBDMODE: wCurMode = GetKbdMode() ; wsprintf(CurModeString, "Current keyboard mode = %i", wCurMode); InvalidateRect(hWnd, NULL, TRUE) ; break; case IDM_F_SETKBDMODE: MessageBox(hWnd, "Press OK to change keyboard mode...", "Sample", MB_OK) ; wCurMode = GetKbdMode() ; if (wCurMode == 1) SetKbdMode(2) ; else if (wCurMode == 2) SetKbdMode(1) ; /* Fill the string CurModeString[] */ SendMessage(hWnd, WM_COMMAND, IDM_F_GETKBDMODE, 0L); InvalidateRect(hWnd, NULL, TRUE) ; break; case IDM_F_GETKBDHOTKEY: bCurHotkey = LOBYTE(GetKbdHotkey()) ; switch (bCurHotkey) { case HK_RCTRL: lstrcpy( szHotkey, "Right Ctrl") ; break ; case HK_LSHIFT: lstrcpy( szHotkey, "Left Shift") ; break ; case HK_RSHIFT: lstrcpy( szHotkey, "Right Shift") ; break ; case HK_SHIFTSHIFT: lstrcpy( szHotkey, "Right Shift + Left Shift") ; break ; case HK_CTRLSHIFT: lstrcpy( szHotkey, "LeftShift+LeftCtrl / RightShift+RightCtrl") ; break ; case HK_ALTSHIFT: lstrcpy( szHotkey, "LeftShift+LeftAlt / RightShift+RightAlt") ; break ; case HK_LCTRL: default: lstrcpy( szHotkey, "Left Ctrl") ; break ; } lstrcpy(CurHotkeyString, "Current hotkey = "); lstrcat(CurHotkeyString, szHotkey) ; InvalidateRect(hWnd, NULL, TRUE) ; break; case IDM_F_SETKBDHOTKEY: bCurHotkey = LOBYTE(GetKbdHotkey()) ; MessageBox(hWnd, "Press OK to scroll hotkey...", "Sample", MB_OK) ; bCurHotkey++; bMaxHotkeys = HIBYTE(GetKbdHotkey()); if (bCurHotkey > bMaxHotkeys) bCurHotkey = 1 ; // = HK_LCTRL SetKbdHotkey((WORD)bCurHotkey) ; /* Fill the string CurHotkeyString[] */ SendMessage(hWnd, WM_COMMAND, IDM_F_GETKBDHOTKEY, 0L); InvalidateRect(hWnd, NULL, TRUE) ; break; case IDM_F_GETKBDDLLSSTATUS: wRetValue = GetKbdDllsStatus() ; if ( (wRetValue & 0x0001) > 0 ) { bPriDllLoaded = TRUE ; lstrcpy (PriLibraryString, "1-st DLL status: Loaded") ; GetPrivateProfileString("boot.description", "keyboard.dll", "", szLayoutName, 64, "system.ini" ) ; lstrcat(PriLibraryString," (layout in 1-st mode: ") ; lstrcat(PriLibraryString,szLayoutName) ; lstrcat(PriLibraryString, ")") ; } else { bPriDllLoaded = FALSE ; lstrcpy (PriLibraryString, "1-st DLL status: Not loaded (default layout: US)") ; } if ( (wRetValue & 0x0002) > 0 ) { bSecDllLoaded = TRUE ; lstrcpy (SecLibraryString, "2-nd DLL status: Loaded") ; GetPrivateProfileString("boot.description", "secondkeyb.dll", "", szLayoutName, 64, "system.ini" ) ; lstrcat(SecLibraryString," (layout in 2-nd mode: ") ; lstrcat(SecLibraryString,szLayoutName) ; lstrcat(SecLibraryString, ")") ; } else { bSecDllLoaded = FALSE ; lstrcpy (SecLibraryString, "2-nd DLL status: Not loaded (default layout: US)") ; } InvalidateRect(hWnd, NULL, TRUE) ; break; case IDM_F_ABOUT: MessageBox(hWnd, "Sample application calls the functions exported by RWUSER.DLL library to show the features of R-WIN keyboard driver.\r\r Copyright (c) 1991-95 Proxima Systems. All rights reserved.", "About Sample", MB_OK) ; break; default: return DefWindowProc(hWnd, Message, wParam, lParam); } break; case WM_KEYUP: if ((wParam == VK_PRI_MODE) || ( wParam == VK_SEC_MODE)) { if (wParam == VK_PRI_MODE) wCurMode = 1 ; else wCurMode = 2 ; MessageBeep(0) ; wsprintf(CurModeString, "Current mode = %i (received WM_KEYUP)", wCurMode); InvalidateRect(hWnd, NULL, TRUE) ; } break; case WM_PAINT: memset(&ps, 0x00, sizeof(PAINTSTRUCT)); hDC = BeginPaint(hWnd, &ps); SetBkMode(hDC, TRANSPARENT); TextOut(hDC, 10, 10, CurModeString, lstrlen(CurModeString)); TextOut(hDC, 10, 30, CurHotkeyString, lstrlen(CurHotkeyString)); TextOut(hDC, 10, 45, PriLibraryString, lstrlen(PriLibraryString)); TextOut(hDC, 10, 60, SecLibraryString, lstrlen(SecLibraryString)); EndPaint(hWnd, &ps); break; case WM_CLOSE: DestroyWindow(hWnd); if (hWnd == hWndMain) PostQuitMessage(0); break; default: return DefWindowProc(hWnd, Message, wParam, lParam); } return 0L; } int nCwRegisterClasses(void) { WNDCLASS wndclass; memset(&wndclass, 0x00, sizeof(WNDCLASS)); wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInst; wndclass.hIcon = LoadIcon(hInst, "SAMPLE"); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wndclass.lpszMenuName = szAppName; wndclass.lpszClassName = szAppName; if(!RegisterClass(&wndclass)) return -1; return(0); } void CwUnRegisterClasses(void) { WNDCLASS wndclass; memset(&wndclass, 0x00, sizeof(WNDCLASS)); UnregisterClass(szAppName, hInst); }